package com.atguigu.srb.core.controller.admin;


import com.atguigu.srb.base.utils.JwtUtils;
import com.atguigu.srb.common.result.R;
import com.atguigu.srb.core.pojo.entity.Borrower;
import com.atguigu.srb.core.pojo.entity.UserInfo;
import com.atguigu.srb.core.pojo.vo.BorrowerApprovalVO;
import com.atguigu.srb.core.pojo.vo.BorrowerAttachVO;
import com.atguigu.srb.core.pojo.vo.BorrowerDetailVO;
import com.atguigu.srb.core.pojo.vo.BorrowerVO;
import com.atguigu.srb.core.service.BorrowerAttachService;
import com.atguigu.srb.core.service.BorrowerService;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.util.List;
import java.util.function.LongPredicate;

/**
 * <p>
 * 借款人 前端控制器
 * </p>
 *
 * @author HuoYongZhuang
 * @since 2021-06-17
 */
@Api(tags = "借款人")
@RestController
@RequestMapping("/admin/core/borrower")
@Slf4j
public class AdminBorrowerController {

    @Resource
    private BorrowerService borrowerService;

    @Resource
    private BorrowerAttachService borrowerAttachService;
//    keyword
    @ApiOperation("获取借款人分页列表")
    @GetMapping("/list/{page}/{limit}")
    public R listPage(@ApiParam(value = "当前页数",required = true)
                      @PathVariable Long page,
                      @ApiParam(value = "每页条数",required = true)
                      @PathVariable Long limit,
                      @ApiParam(value = "查询关键字",required = false)
                      String keyword){

        Page<Borrower> pageParam = new Page<Borrower>(page,limit);
        IPage<Borrower> pageModel = borrowerService.listPage(pageParam, keyword);

        return  R.ok().data("pageModel",pageModel);


    }


    @ApiOperation("获取借款人信息")
    @GetMapping("/show/{id}")
    public R show(@ApiParam(value = "借款人id", required = true)
                      @PathVariable Long id){
        BorrowerDetailVO borrowerDetailVO = borrowerService.getBorrowerDetailVOById(id);
        return R.ok().data("borrowerDetailVO", borrowerDetailVO);

    }

//    @ApiOperation("aaa")
//    @GetMapping("/aaa/{id}")
//    public R aaa(@ApiParam(value = "借款人id", required = true)
//                  @PathVariable Long id){
//        List<BorrowerAttachVO> borrowerAttachVOS = borrowerAttachService.selectBorrowerAttachVOList(id);
//        return R.ok().data("borrowerAttachVOS", borrowerAttachVOS);
//
//    }

    @ApiOperation("借款额度审批")
    @PostMapping("/approval")
    public R approval(@RequestBody BorrowerApprovalVO borrowerApprovalVO){
        borrowerService.approval(borrowerApprovalVO);
        return R.ok().message("审批完成");
    }









}

